package Modele; 


import java.util.ArrayList; 
import java.util.Collections;
import java.util.Comparator;

public class Repertoire {
	
	private ArrayList<Contact> listContact; 
	
	public Repertoire(){
		listContact= new ArrayList<Contact>(); 
	}
	
	public void addContact(Contact newContact){
		listContact.add(newContact); 
	}
	
	public void deleteContact(String[] c){
		
		int i= research(c);
		listContact.remove(i); 
	}
	
	public int research(String[] str){
		
		for(int i=0; i<listContact.size();i++)
			if(listContact.get(i).getNom().equals(str[1]) && listContact.get(i).getPrenom().equals(str[0]))
				return i;
		return -1;
	}
	
	public void triDate(){
		
		Collections.sort(listContact,new DateComparator());

	}
	
	public void triAlpha(){
		
		Collections.sort(listContact,new AlphaComparator());
		
	}
	
	public ArrayList<String> toStringBasic(String cat){
		ArrayList<String> a = new ArrayList<String>(); 
		int i;
		if(!listContact.isEmpty()){
		for( i=0; i<listContact.size(); i++)
		{   
			if(listContact.get(i).getVirtualGroup().equals(cat))
				a.add(listContact.get(i).toStringBasic());
		}
		}
		return a; 
	}
	
	public int getSize(){
		return listContact.size();
	}

	public ArrayList<Contact> getListContact() {
		return listContact;
	}

	public void setListContact(ArrayList<Contact> listContact) {
		this.listContact = listContact;
	}
	
	public Contact getContact(int i) {
		return listContact.get(i);
	}
	
	public String getContactInfo(String[] str){
		for(int i=0; i<listContact.size();i++)
			if(listContact.get(i).getNom().equals(str[1]) && listContact.get(i).getPrenom().equals(str[0]))
				return listContact.get(i).toString();
		
		return "Inconnu";
	}
	
	public void modifierContact(String[] c,Contact newContact){
		 int index = research(c);
		 
		 listContact.get(index).setNom(newContact.getNom());
		 listContact.get(index).setPrenom(newContact.getPrenom());
		 listContact.get(index).setHomeAdress(newContact.getHomeAdress());
		 listContact.get(index).setWorkAdress(newContact.getWorkAdress());
		 listContact.get(index).setMobilePersonalNumber(newContact.getMobilePersonalNumber());
		 listContact.get(index).setOfficeWorkNumber(newContact.getOfficeWorkNumber());
		 listContact.get(index).setHomepage(newContact.getHomepage());
	}
	
}
